//
//  mySliderVC.m
//  qqqqqq
//
//  Created by iOSer on 16/6/8.
//  Copyright © 2016年 iOSer. All rights reserved.
//

#import "mySliderVC.h"

@interface mySliderVC ()
@property(nonatomic,strong) UISlider *mySlider;
@property(nonatomic,strong) UILabel *label;
@property(nonatomic,strong) UILabel *label2;
@end

@implementation mySliderVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"自定义滑动控件";
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    [self setupUI];
    [self setupSlider];
    
    
}


-(void)setupUI{
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 50, 100)];
    _label.textColor = [UIColor blackColor];
    [self.view addSubview:self.label];
    
    self.label2 = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];
    _label2.textColor = [UIColor blackColor];
    [self.view addSubview:_label2];
}


-(void)setupSlider{
    UIImage *thumbImage = [UIImage imageNamed:@"jianli_huakuai"];
    
    self.mySlider=[[UISlider alloc]initWithFrame:CGRectMake(30, 320, 257, 50)];
    _mySlider.backgroundColor = [UIColor clearColor];
    _mySlider.value=0;
    _mySlider.minimumValue=0;
    _mySlider.maximumValue=5;
    
    [_mySlider setMinimumTrackImage:[UIImage imageNamed:@"jianli_huadongtiao"] forState:UIControlStateNormal];
    [_mySlider setMaximumTrackImage:[UIImage imageNamed:@"jianli_huadongtiao2"] forState:UIControlStateNormal];
    //注意这里要加UIControlStateHightlighted的状态，否则当拖动滑块时滑块将变成原生的控件
    [_mySlider setThumbImage:thumbImage forState:UIControlStateHighlighted];
    [_mySlider setThumbImage:thumbImage forState:UIControlStateNormal];
    //设置滑动条颜色
    //    [_mySlider setMinimumTrackTintColor:HEXColor(0x00ced1, 1)];
    //
    //    [_mySlider setMaximumTrackTintColor:HEXColor(0xefefef, 1)];
    
    //    [_mySlider setThumbTintColor:[UIColor blueColor]];
    //滑块拖动时的事件
    [_mySlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    //滑动拖动后的事件
        [_mySlider addTarget:self action:@selector(sliderDragUp:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_mySlider];
}
-(void)sliderDragUp:(UISlider *)slider{
    self.label.text =[NSString stringWithFormat:@"%.f",slider.value];
    
    if(slider.value >0.5 && slider.value <1.5){
        slider.value = 1;
        self.label2.text = @"失望";
    }else if(slider.value >1.5 && slider.value <2.5){
        slider.value = 2;
        self.label2.text = @"不满";
    }else if(slider.value >2.5 && slider.value <3.5){
        slider.value = 3;
        self.label2.text = @"一般";
    }else if(slider.value >3.5 && slider.value <4.5){
        slider.value = 4;
        self.label2.text = @"满意";
    }else if(slider.value >4.5 && slider.value <5){
        slider.value  = 5;
        self.label2.text = @"惊喜";
    }else if(slider.value < 0.5){
        slider.value = 0;
        self.label2.text = @"";
    }

}
-(void)sliderValueChanged:(UISlider *)slider{
    
    self.label.text =[NSString stringWithFormat:@"%.f",slider.value];
    
    if(slider.value >0.5 && slider.value <1){
        slider.value = 1;
        self.label2.text = @"失望";
    }else if(slider.value >1.5 && slider.value <2){
        slider.value = 2;
        self.label2.text = @"不满";
    }else if(slider.value >2.5 && slider.value <3){
        slider.value = 3;
        self.label2.text = @"一般";
    }else if(slider.value >3.5 && slider.value <4){
        slider.value = 4;
        self.label2.text = @"满意";
    }else if(slider.value >4.5 && slider.value <5){
        slider.value  = 5;
        self.label2.text = @"惊喜";
    }else if(slider.value == 0){
        self.label2.text = @"";
    }
    
}

@end
